package core

import (
	"github.com/spf13/viper"
)

func AnalyConf() map[string]string {
	vipe := viper.New()
	vipe.AddConfigPath("./../conf")
	vipe.SetConfigName("config")
	vipe.SetConfigType("yaml")

	var reVal = make(map[string]string)
	//邮件
	smtpStr := vipe.GetString("mail.smtp")
	if smtpStr == "" {
		smtpStr = "smtp.qq.com"
	}
	reVal["mailSmtp"] = smtpStr
	mailPort := vipe.GetString("mail.port")
	if mailPort == "" {
		mailPort = "465"
	}
	reVal["mailPort"] = mailPort

	mailFrom := vipe.GetString("mail.from")
	if mailFrom == "" {
		mailFrom = "1343669171@qq.com"
	}
	reVal["mailFrom"] = mailFrom
	authcode := vipe.GetString("mail.authcode")
	if authcode == "" {
		authcode = "hkcgpomycbcsbadb"
	}
	reVal["mailAuthcode"] = authcode

	//数据库
	dbHost := vipe.GetString("db.host")
	if dbHost == "" {
		dbHost = "127.0.0.1"
	}
	reVal["dbHost"] = dbHost
	dbPort := vipe.GetString("db.port")
	if dbPort == "" {
		dbPort = "3306"
	}
	reVal["dbPort"] = dbPort

	dbUser := vipe.GetString("db.user")
	if dbUser == "" {
		dbUser = "root"
	}
	reVal["dbUser"] = dbUser
	dbPasswd := vipe.GetString("db.passwd")
	if dbPasswd == "" {
		dbPasswd = "root"
	}
	reVal["dbPasswd"] = dbPasswd
	dbName := vipe.GetString("db.dbname")
	if dbName == "" {
		dbName = "jslog"
	}
	reVal["dbName"] = dbName

	//redis
	redisHost := vipe.GetString("redis.host")
	if redisHost == "" {
		redisHost = "127.0.0.1"
	}
	reVal["redisHost"] = redisHost
	redisPort := vipe.GetString("v.port")
	if redisPort == "" {
		redisPort = "6379"
	}
	reVal["redisPort"] = redisPort
	redisPasswd := vipe.GetString("redis.passwd")
	if redisPasswd == "" {
		redisPasswd = "1"
	}
	reVal["redisPasswd"] = redisPasswd

	//缓存
	cacheExpiration := vipe.GetString("cache.expiration")
	if cacheExpiration == "" {
		cacheExpiration = "3"
	}
	reVal["cacheExpiration"] = cacheExpiration
	cacheCleanup := vipe.GetString("cache.cleanup")
	if cacheCleanup == "" {
		cacheCleanup = "1"
	}
	reVal["cacheCleanup"] = cacheCleanup

	return reVal
}
